import React, { useEffect, useState } from 'react';
import { Dialog, DialogContent } from "@/components/ui/dialog";
import { DocumentEditor } from "@onlyoffice/document-editor-react";


export default function WpsEdit() {
  const [showDialog, setShowDialog] = useState(false);
  const [selectedText, setSelectedText] = useState("");

  const onDocumentReady = function (event) {
    console.log("Document is loaded");
  };

  const onLoadComponentError = function (errorCode, errorDescription) {
    switch (errorCode) {
      case -1: // Unknown error loading component
        console.log(errorDescription);
        break;

      case -2: // Error load DocsAPI from http://documentserver/
        console.log(errorDescription);
        break;

      case -3: // DocsAPI is not defined
        console.log(errorDescription);
        break;
    }
  };

  return (
    <DocumentEditor
      id="docxEditor"
      documentServerUrl="http://localhost:3000"
      config={{
        "document": {
          "fileType": "docx",
          "key": "Khirz6zTPdfd7",
          "title": "Example Document Title.docx",
          "url": "https://example.com/url-to-example-document.docx"
        },
        "documentType": "word",
        "editorConfig": {
          "callbackUrl": "https://example.com/url-to-callback.ashx"
        },
        "events": {
          "onDocumentReady": onDocumentReady
        }
      }}
      onLoadComponentError={onLoadComponentError}
    />
  );
} 